package psrc.logic.pages.representante;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import psrc.logic.pages.base.ControllerBase;
import psrc.logic.util.beans.RepresentanteBean;

public class SendRepresentanteRemoveController extends ControllerBase {

	private static final long serialVersionUID = 1L;

	String[] representanteCheckbox;
	
		@Override
		public String executeController() throws Exception {
			RepresentanteModel model = new RepresentanteModel();
			List<RepresentanteBean> todosRepresentantes = model.getRepresentantesList();
			List<RepresentanteBean> representantesParaRemover = new ArrayList<RepresentanteBean>();
			List<String> idsParaRemover = Arrays.asList(getRepresentanteCheckbox());
			
			for (RepresentanteBean prod : todosRepresentantes){
				if (idsParaRemover.contains(prod.getIdRepresentante() )){
					representantesParaRemover.add(prod);
				}
			}
			try {
				if (model.removeRepresentante(representantesParaRemover)){
					return SUCCESS;
				}
			} catch (Exception e) {
				addActionError(getText("error.constraint"));
			}
			return ERROR;
		}

		/**
		 * @return the representanteCheckbox
		 */
		public String[] getRepresentanteCheckbox() {
			return representanteCheckbox;
		}

		/**
		 * @param representanteCheckbox the representanteCheckbox to set
		 */
		public void setRepresentanteCheckbox(String[] representanteCheckbox) {
			this.representanteCheckbox = representanteCheckbox;
		}



}
